package com.wgj.android.utils;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.TextView;

import com.jiaai.xui.icon.typeface.IIcon;
import com.jiaai.xui.icon.utils.IconUtils;
import com.jiaai.xui.utils.XDensityUtils;
import com.wgj.android.utils.fonat.IconFonat;

import org.w3c.dom.Text;

/**
 * Created by Administrator on 2017/11/5.
 */

public class TextViweUtils {

    public  static void setDrawableLeft(TextView view, IIcon iIcon,int color,int dp){
        Drawable drawable= getDrawable(view.getContext(), iIcon, color, dp);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        view.setCompoundDrawables(drawable, null, null, null);
    }

    public static void setDrawableRight(TextView view, IIcon iIcon,int color,int dp){
        Drawable drawable= getDrawable(view.getContext(), iIcon, color, dp);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        view.setCompoundDrawables(null, null, drawable, null);
    }

    public static void setDrawableTop(TextView view, IIcon iIcon,int color,int dp){
        Drawable drawable= getDrawable(view.getContext(), iIcon, color, dp);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        view.setCompoundDrawables(null, drawable, null, null);
    }
    public static void setDrawableBottom(TextView view, IIcon iIcon,int color,int dp){
        Drawable drawable= getDrawable(view.getContext(), iIcon, color, dp);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        view.setCompoundDrawables(null, null, null, drawable);
    }

    private static  Drawable getDrawable(Context context,IIcon iIcon, int color, int dp){
        Drawable drawable= IconUtils.getDrawble(context, iIcon, color, XDensityUtils.dp2px(dp));
        return drawable;
    }
}
